FROM eclipse-temurin:17-jdk-jammy AS builder
WORKDIR /app-builder
COPY target/wmall-gateway.jar wmall-gateway.jar
RUN java -Djarmode=layertools -jar wmall-gateway.jar extract

FROM eclipse-temurin:17-jdk-jammy
WORKDIR /app/wmall-gateway
COPY --from=builder /app-builder/dependencies/ ./
COPY --from=builder /app-builder/spring-boot-loader/ ./
COPY --from=builder /app-builder/snapshot-dependencies/ ./
COPY --from=builder /app-builder/application/ ./

# 暴露端口（与application.properties中配置的端口一致）
EXPOSE 18000

# 优化JVM参数：堆内存默认先50%，最大75% （其他内存还要 JVM 非堆使用）
ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -XX:InitialRAMPercentage=50.0 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/app/wmall-gateway/heap-dump.hprof -Dspring.profiles.active=local -Denv=DEV"

# 使用分层启动
ENTRYPOINT ["sh", "-c", "exec java ${JAVA_OPTS} org.springframework.boot.loader.launch.JarLauncher"]